/* 
 *  <copyright file="OnDeathBase.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;
using System.Text;

using SobrietyEngine.Events.Actor;
using SobrietyEngine.Events;
using SobrietyEngine.Guids;
using SobrietyEngine.Common;

namespace SobrietyEngine.Components.OnDeath
{
    public abstract class OnDeathBase : BaseComponent, IComponent, IEventListener
    {
        public OnDeathBase():base()
        {
        }

        public override Boolean InitComponent()
        {
            base.InitComponent();
            RegisterEventListeners();
            return true;
        }

        public virtual void RegisterEventListeners()
        {
            ParentActor.EventRouter.AddEventListener(typeof(ActorDied), this);
        }

        public virtual void UnregisterEventListeners()
        {
            ParentActor.EventRouter.RemoveEventListener(typeof(Events.Actor.ActorDied), this);
        }

        abstract public void HandleEvent(Event e);

        public override void Remove()
        {
            base.Remove();
            UnregisterEventListeners();
        }
    }
}